package com.mcptt.config.ue.initial.sub;

import java.util.List;

import org.jdom.Element;
import org.jdom.JDOMException;

import com.cloudptt.api.comm.CheckData;
import com.cloudptt.api.product.log.Log;
import com.mcptt.config.local.SysConfig;
import com.mcptt.config.ue.initial.sub.sub.AnyExt;
import com.mcptt.config.ue.initial.sub.sub.AppServerInfo;
import com.mcptt.config.ue.initial.sub.sub.HPLM;
import com.mcptt.config.ue.initial.sub.sub.Timers;

public class OnNetwork {
	
	public static final String Name = "on-network";
	private static final String Name_GmsUri = "GMS-URI";
	private static final String Name_GroupCreationXUI = "group-creation-XUI";
	private static final String Name_CmsXcapRootURI = "CMS-XCAP-root-URI";
	private static final String Name_GmsXcapRootURI = "GMS-XCAP-root-URI";
	private static final String Name_IntegrityProtectionEnabled = "integrity-protection-enabled";
	private static final String Name_ConfidentialityProtectionEnabled = "confidentiality-protection-enabled";
	private static final String Name_AffiliationEnabled = "affiliation-enabled";
//	private static final String Name_Sip = "sip";
//	private static final String Name_Domain = "domain";
//	private static final String Name_Psi_Cms = "cms-psi";
//	private static final String Name_Psi_Gms = "gms-psi";
//	private static final String Name_Psi_McPtt = "mcptt-psi";
//	private static final String Name_Psi_McVideo = "mcvideo-psi";
//	private static final String Name_Psi_McData = "mcdata-psi";
	
	private Timers timers = null;

	private HPLM hplm = null;
	private AppServerInfo appServerInfo = null;

//	private String sip = null;
//	private String domain = SysConfig.Default_Domain;
//	private String psiCms = SysConfig.Default_PsiCms;
//	private String psiGms = SysConfig.Default_PsiGms;
//	private String psiMcPtt = SysConfig.Default_PsiMcPtt;
//	private String psiMcVideo = SysConfig.Default_PsiMcVideo;
//	private String psiMcData = SysConfig.Default_PsiMcData;



	private String gmsUri = null;//gms psi
	private String groupCreationXUI = null;
	private String cmsXcapRootUri = null;
	private String gmsXcapRootUri = null;

	private boolean integrityProtectionEnabled = false;
	private boolean confidentialityProtectionEnabled = false;

	private boolean affiliationEnabled = false;

	private AnyExt anyExt = null;

	public void parse(Element elem) throws JDOMException
	{
		if(elem == null)
		{
			return;
		}
		List<Element> list = elem.getChildren();//��ø��ڵ���ӽڵ�  
		for(Element subElem:list) 
		{
			String name = subElem.getName();
			Log.debug(this.getClass(), "name = " + name);
			
			if(name == null
					|| name.length() <= 0)
			{
				return;
			}
			
			if(name.equals(Timers.Name))
			{
				timers = new Timers();
				timers.parse(subElem);
			}
			else if(name.equals(HPLM.Name))
			{
				hplm = new HPLM();
				hplm.parse(subElem);
			}
			else if(name.equals(AppServerInfo.Name))
			{
				appServerInfo = new AppServerInfo();
				appServerInfo.parse(subElem);
			}
//			else if(name.equals(Name_Domain))
//			{
//				String str = subElem.getText();
//				if(str != null
//					&& str.length() > 0)
//				{
//					domain = str;
//				}
//			}
//			else if(name.equals(Name_Psi_Cms))
//			{
//				String str = subElem.getText();
//				if(str != null
//						&& str.length() > 0)
//				{
//					psiCms = str;
//				}
//			}
//			else if(name.equals(Name_Psi_Gms))
//			{
//				String str = subElem.getText();
//				if(str != null
//						&& str.length() > 0)
//				{
//					psiGms = str;
//				}
//			}
//			else if(name.equals(Name_Psi_McPtt))
//			{
//				String str = subElem.getText();
//				if(str != null
//						&& str.length() > 0)
//				{
//					psiMcPtt = str;
//				}
//			}
//			else if(name.equals(Name_Psi_McVideo))
//			{
//				String str = subElem.getText();
//				if(str != null
//						&& str.length() > 0)
//				{
//					psiMcVideo = str;
//				}
//			}
//			else if(name.equals(Name_Psi_McData))
//			{
//				String str = subElem.getText();
//				if(str != null
//						&& str.length() > 0)
//				{
//					psiMcData = str;
//				}
//			}
			else if(name.equals(Name_GmsUri))
			{
				gmsUri = subElem.getText();
			}
			else if(name.equals(Name_GroupCreationXUI))
			{
				groupCreationXUI = subElem.getText();
			}
			else if(name.equals(Name_CmsXcapRootURI))
			{
				cmsXcapRootUri = subElem.getText();
			}
			else if(name.equals(Name_GmsXcapRootURI))
			{
				gmsXcapRootUri = subElem.getText();
			}
			else if(name.equals(Name_IntegrityProtectionEnabled))
			{
				String val = subElem.getText();
				integrityProtectionEnabled = CheckData.parseBoolean(val);
			}
			else if(name.equals(Name_ConfidentialityProtectionEnabled))
			{
				String val = subElem.getText();
				confidentialityProtectionEnabled = CheckData.parseBoolean(val);
			}
			else if(name.equals(Name_AffiliationEnabled))
			{
				String val = subElem.getText();
				affiliationEnabled = CheckData.parseBoolean(val);
			}
			else if(name.equals(AnyExt.Name))
			{
				anyExt = new AnyExt();
				anyExt.parse(subElem);
			}
		}  
	}
	
	public AppServerInfo getAppServerInfo()
	{
	    return appServerInfo;
	}
	
	public Timers getTimers() {
		return timers;
	}

//	public String getDomain() {
//		return domain;
//	}
//
//	public String getPsiCms() {
//		return psiCms;
//	}
//
//	public String getPsiGms() {
//		return psiGms;
//	}
//
//	public String getPsiMcPtt() {
//		return psiMcPtt;
//	}
//
//	public String getPsiMcVideo() {
//		return psiMcVideo;
//	}
//
//	public String getPsiMcData() {
//		return psiMcData;
//	}


	public String getGroupCreationXUI() {
		return groupCreationXUI;
	}

	public String getCmsXcapRootUri() {
		return cmsXcapRootUri;
	}

	public String getGmsXcapRootUri() {
		return gmsXcapRootUri;
	}

	public String getGmsUri() {
		return gmsUri;
	}

	public boolean isIntegrityProtectionEnabled() {
		return integrityProtectionEnabled;
	}

	public boolean isConfidentialityProtectionEnabled() {
		return confidentialityProtectionEnabled;
	}

	public boolean isAffiliationEnabled() {
		return affiliationEnabled;
	}

	public AnyExt getAnyExt() {
		return anyExt;
	}
	public String toString()
	{
		StringBuffer strBuf = new StringBuffer("\r\n");
		strBuf.append("<").append(Name).append(">").append("\r\n");
		strBuf.append(timers);
		strBuf.append(hplm);
		strBuf.append(appServerInfo);
//		strBuf.append("    ").append("<").append(Name_Domain).append(">");
//		strBuf.append(domain);
//		strBuf.append("</").append(Name_Domain).append(">").append("\r\n");
//		strBuf.append("    ").append("<").append(Name_Psi_Cms).append(">");
//		strBuf.append(psiCms);
//		strBuf.append("</").append(Name_Psi_Cms).append(">").append("\r\n");
//		strBuf.append("    ").append("<").append(Name_Psi_Gms).append(">");
//		strBuf.append(psiGms);
//		strBuf.append("</").append(Name_Psi_Gms).append(">").append("\r\n");
//
//		strBuf.append("    ").append("<").append(Name_Psi_McPtt).append(">");
//		strBuf.append(psiMcPtt);
//		strBuf.append("</").append(Name_Psi_McPtt).append(">").append("\r\n");
//		strBuf.append("    ").append("<").append(Name_Psi_McVideo).append(">");
//		strBuf.append(psiMcVideo);
//		strBuf.append("</").append(Name_Psi_McVideo).append(">").append("\r\n");
//		strBuf.append("    ").append("<").append(Name_Psi_McData).append(">");
//		strBuf.append(psiMcData);
//		strBuf.append("</").append(Name_Psi_McData).append(">").append("\r\n");

		strBuf.append("    ").append("<").append(Name_GmsUri).append(">");
		strBuf.append(gmsUri);
		strBuf.append("</").append(Name_GmsUri).append(">").append("\r\n");

		strBuf.append("    ").append("<").append(Name_GroupCreationXUI).append(">");
		strBuf.append(groupCreationXUI);
		strBuf.append("</").append(Name_GroupCreationXUI).append(">").append("\r\n");
		
		strBuf.append("    ").append("<").append(Name_CmsXcapRootURI).append(">");
		strBuf.append(cmsXcapRootUri);
		strBuf.append("</").append(Name_CmsXcapRootURI).append(">").append("\r\n");
		strBuf.append("    ").append("<").append(Name_GmsXcapRootURI).append(">");
		strBuf.append(gmsXcapRootUri);
		strBuf.append("</").append(Name_GmsXcapRootURI).append(">").append("\r\n");

		strBuf.append("    ").append("<").append(Name_IntegrityProtectionEnabled).append(">");
		strBuf.append(integrityProtectionEnabled);
		strBuf.append("</").append(Name_IntegrityProtectionEnabled).append(">").append("\r\n");
		strBuf.append("    ").append("<").append(Name_ConfidentialityProtectionEnabled).append(">");
		strBuf.append(confidentialityProtectionEnabled);
		strBuf.append("</").append(Name_ConfidentialityProtectionEnabled).append(">").append("\r\n");

		strBuf.append("    ").append("<").append(Name_AffiliationEnabled).append(">");
		strBuf.append(affiliationEnabled);
		strBuf.append("</").append(Name_AffiliationEnabled).append(">").append("\r\n");

		strBuf.append(anyExt);
		
		strBuf.append("</").append(Name).append(">").append("\r\n");

		return strBuf.toString();
	}
}
